"""作业一：
在服务器上自己的crmeb
1、登录
2、添加用户分组——》删除刚才新增的用户分组
3、添加是否成功，断言；删除是否成功，断言
组件化，元素与脚本分离"""
"""import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from ele import *
class CrembGroup:
    def __init__(self,url,brwoser):
        self.brwoser = brwoser
        self.brwoser.get(url)
        self.brwoser.maximize_window()
        self.brwoser.implicitly_wait(15)
        time.sleep(5)
    def login(self,username,password):
        # 输入账号
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(user_ele))[0].send_keys(username)
        # 输入密码
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(pwd_ele))[1].send_keys(password)
        #点击登录
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located(dl_ele)).click()

    def add_group(self,groupName):
        self.groupName = groupName
        time.sleep(5)
        # 点击用户
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(yh_ele))[1].click()
        time.sleep(2)
        # 点击用户分组
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located(userGroup_ele)).click()
        time.sleep(2)
        # 点击添加分组
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located(add_group_ele)).click()
        time.sleep(2)
        # 输入分组名称
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(input_group_ele))[2].send_keys(groupName)
        time.sleep(2)
        # 点击确定
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(accept_ele))[2].click()
        time.sleep(2)

        # 判读添加是否成功
    def assert_add(self):
        text = WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH,f"//*[text()='{self.groupName}']"))).text
        assert text == self.groupName

        # 删除用户分组
    def delete_group(self):
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(delete_ele))[-1].click()
        time.sleep(2)
        # 点击确定
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(del_accept_ele))[2].click()
        time.sleep(2)
       
if __name__ == '__main__':
    driver = webdriver.Chrome()
    url ="http://121.40.86.4:8899/admin/login"
    c1 = CrembGroup(url,driver)
    c1.login("admin","Aa010903!")
    c1.add_group("liuhao")
    c1.assert_add()
    c1.delete_group()"""


"""作业二：
QQ音乐登录：https://y.qq.com/portal/pop_login.html"""

"""
import time
from selenium import  webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://y.qq.com/portal/pop_login.html")
driver.maximize_window()
driver.implicitly_wait(15)
# 定位iframe内联框架
iframe = driver.find_element(By.TAG_NAME,"iframe")
# 跳进iframe
driver.switch_to.frame(iframe)
time.sleep(2)
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.ID,"img_out_2142714362"))).click()
time.sleep(2)
"""

"""作业三-crmeb：
1、添加用户标签——》删除刚才新增的用户标签
2、添加是否成功，断言；删除是否成功，断言"""
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class GroupLogo:
    def __init__(self,url,brwoser):
        self.brwoser = brwoser
        self.brwoser.get(url)
        self.brwoser.maximize_window()
        self.brwoser.implicitly_wait(15)
    def login(self,user,password):
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"el-input__inner")))[0].send_keys("admin")
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"el-input__inner")))[1].send_keys("Aa010903!")
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH,"//*[@id='app']/div[1]/div[1]/div[2]/form/div[3]/div/button"))).click()
    def add_group(self,groupName):
        self.groupName = groupName
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"font12")))[1].click()
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH, "//*[text()='用户标签']"))).click()
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH, "//*[text()='添加标签']"))).click()
        time.sleep(2)
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"el-input__inner")))[2].click()
        time.sleep(2)
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"el-select-dropdown__item")))[5].click()
        time.sleep(2)
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-input__inner")))[3].send_keys(groupName)
        time.sleep(2)
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-button")))[2].click()

        time.sleep(5)
    def assert_add(self):
        text = WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH,f"//*[text()='{self.groupName}']"))).text
        assert text == self.groupName
        time.sleep(2)
    def delete_logo(self):
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.XPATH, "//*[text()='删除']")))[-1].click()
        time.sleep(2)
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-button")))[2].click()
        time.sleep(2)
if __name__ == '__main__':
    driver = webdriver.Chrome()
    url = "http://121.40.86.4:8899/admin/login"
    c1 = GroupLogo(url,driver)
    c1.login("admin","Aa010903!")
    c1.add_group("liuhao")
    c1.assert_add()
    c1.delete_logo()

